﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AssetsAction
{
    public static string AssetsType;
    public enum ActionType
    {
        CheckAssets,
        Downloading,
        UnpackFile,
        UnpackZip,
        CheckFile
    }
    protected long _pos;
    protected long _len;
    protected bool _done = false;
    protected float _progress;
    public long Position { get => _pos; }
    public long Length { get => _len; }
    public virtual float Progress {
        get
        {
            return _progress;
        } 
    }
    public virtual string Tips { get { return ""; } }
    public bool Done { get => _done; }
    public virtual void Reset()
    {
        _done = false;
    }
    public virtual void Update()
    {

    }
    protected static List<AssetsAction> actions = new List<AssetsAction>();
    public static T GetStep<T>()where T:AssetsAction
    {
        for(int i=0;i<actions.Count;i++)
        {
            T t = actions[i] as T;
            if (t != null)
                return t;
        }
        return null;
    }
    public static T AddSetp<T>() where T : AssetsAction, new()
    {
        T t = new T();
        actions.Add(t);
        return t;
    }
    public static void AddSetp<T>(T t)where T : AssetsAction
    {
        actions.Add(t);
    }
    public static void UpdateState()
    {
        for (int i = 0; i < actions.Count; i++)
            actions[i].Update();
    }
    public static AssetsAction GetCurrentStep()
    {
        for (int i = 0; i < actions.Count; i++)
            if (!actions[i]._done)
                return actions[i];
        return null;
    }
}